﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using Entity.Model;
using SystemFrameWork.Enums;

namespace BLL
{
    public class Sys_UserManagement : EntityManagement
    {
        private Sys_UserDAO sys_UserDao = new Sys_UserDAO();

        /// <summary>
        /// check the use account is existed or not.
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pasWord"></param>
        /// <returns></returns>
        public Sys_User CheckUser(string userName, string passWord)
        {
            return this.sys_UserDao.CheckUser(userName, passWord);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public Sys_User LoadUserByName(string userName)
        {
            return this.sys_UserDao.LoadUserByName(userName);
        }

        /// <summary>
        /// get the moduels which bind up with his function roles from the system 
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public string GetFunctionalModule(Sys_User user)
        {
            return this.sys_UserDao.GetFunctionalModule(user);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        public void Insert(Sys_RoleUser sru)
        {
            this.sys_UserDao.Insert(sru);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        public void Insert(Sys_User user)
        {
            this.sys_UserDao.Insert(user);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="suv"></param>
        /// <returns></returns>
        public List<SysUserView> LoadSysUserViewByCondition(SysUserView suv)
        {
            return this.sys_UserDao.LoadSysUserViewByCondition(suv);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="listUserID"></param>
        /// <returns></returns>
        public Sys_User LoadSysUserByID(Guid userID)
        {
            return this.sys_UserDao.LoadSysUserByID(userID);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public SysUserView LoadSysUserViewByID(Guid userID)
        {
            return this.sys_UserDao.LoadSysUserViewByID(userID);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public List<Sys_RoleUser> LoadSys_RoleUser(Guid userID)
        {
            return this.sys_UserDao.LoadSys_RoleUser(userID);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="listUserID"></param>
        public void Delete(List<Sys_User> listUser)
        {

            foreach (Sys_User su1 in listUser)
            {
                Sys_User su = this.LoadSysUserByID(su1.ID);
                this.sys_UserDao.Delete(su);
                List<Sys_RoleUser> listRole = this.sys_UserDao.LoadSys_RoleUser(su1.ID);
                foreach (Sys_RoleUser sr in listRole)
                {
                    this.sys_UserDao.Delete(sr);
                }
            }

            base.UpdateChanges();
        }

        /// <summary>
        /// the list must be in the same session of the data base
        /// </summary>
        /// <param name="list"></param>
        public void Delete(List<Sys_RoleUser> list)
        {
            foreach (Sys_RoleUser sru in list)
            {
                this.sys_UserDao.Delete(sru);
            }
        }
    }
}
